//Parser object that contains all parser for all skins
//Parser = function Parser() {}; //No need to initialize

/**
 * @function namespace/signatrue - Component type : Control type : Parser.formskin : Parser.impl : html
 * conf - configuration properties for layout
 * prop - properties
 * parentconf - parent element conf
 * parentprop - parent element prop
 */
/*Parser["control:radio:default:Json2htmlParser:html"] = function(conf, prop, parentconf, parentprop) {
	Parser.log(JSON.stringify(parentconf));
	Parser.log(JSON.stringify(parentprop));
	
	var dpval = prop[prop["dataprovider"]];
	
	return '<span class="label"'+
			(prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
			+ '>'
			+ (required ? '<span class="xh">*</span>' : '')
			//+ prop["i18nname-" + Parser.lang] + '</span>'
			+ '${i18nname-'+Parser.lang+'}</span>'
			+ '<span class="item">'
			+ '<span style="line-height:30px;" ng-repeat="i in m.enu[\''+dpval+'\']">'
			+ '<input class="radio" type="radio"'
			+ ' id="${id}_{{i.key}}"'
			+ ' name="${id}" value="{{i[0]}}" '
			+ ' ng-model="b.${databinding}"'
			+ ' />'
			+ '<label for="${id}_{{i[0]}}">{{i[1]}}</label>'
			+ '</span>'
			+ '</span>';
};*/

/*Parser["control:radio:bootstrap-blue:Json2htmlParser:html"] = function(conf, prop, parentconf, parentprop) {
	Parser.log(JSON.stringify(parentconf));
	Parser.log(JSON.stringify(parentprop));
	
	var fmdcols = parseInt(parentconf.fmdcols);
	var cols = [1,fmdcols-1];
	if(fmdcols>3) {
		cols = [2,fmdcols-2];
	}
	var dpval = prop[prop["dataprovider"]];
	
	return '<div class="col-md-'+cols[0]+'">'+
		    '<p'+
		    (prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '') +
		    '>'+prop["i18nname-"+Parser.lang]+
		    (required ? '<span class="xh">*</span>' : '') +
		    '</p>'+
		    '</div>'+
		    '<div class="col-md-'+cols[1]+'">'
		    + '<div>'
			+ '<label class="checkbox-inline" for="${id}_{{i[0]}}" ng-repeat="i in m.enu[\''+dpval+'\']">'
			+ '<input type="radio"'
			+ ' id="${id}_{{i.key}}"'
			+ ' name="${id}" value="{{i[0]}}" '
			+ ' ng-model="b.${databinding}"'
			+ ' />{{i[1]}}'
			+ '</label>'
			+ '<label for="${id}_{{i[0]}}">{{i[1]}}</label>'
			+ '</div>'
			+ '</div>';
};*/


/*Parser["control:radio:default:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		Parser.parseDataProvider(conf.id);
		
		s += '<span class="label"'+
				(prop["i18ntip-"+Parser.lang] ? (' original-title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
				+ '>'
				+ (required ? '<span class="xh">*</span>' : '')
				+ prop["i18nname-"+Parser.lang] + '</span>'
				+ '<span class="item">'
				+ '<span style="line-height:30px;" ng-repeat="i in m.enu[\''+conf.id+'\']">'
				+ '<input class="radio" type="radio"'
				+ ' id="'+conf.id+'_{{i.key}}"'
				+ ' name="'+conf.id+'" value="{{i[0]}}" '
				+ ' ng-model="b.'+prop.databinding+'"'
				+ ' />'
				+ '<label for="'+conf.id+'_{{i[0]}}">{{i[1]}}</label>'
				+ '</span>'
				+ '</span>';
	}
	return s;
};*/

Parser["control:radio:bootstrap-blue:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		Parser.parseDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data.databinding = prop.databinding;
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		transform.html = '<div class="col-md-'+cols[0]+'">'+
		    '<p'+
		    (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '') +
		    (prop.hideLabel=='1' ? ' style="display:none;"' : '')+
		    '>'+prop["i18nname-"+Parser.lang]+
		    (required ? '<span class="xh">*</span>' : '') +
		    (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')+
		    '</p>'+
		    '</div>'+
		    '<div class="col-md-'+cols[1]+'">'
		    + '<div id="${id}">'
			+ '<label class="checkbox-inline" for="${id}_{{i[0]}}" ng-init="p_index=$index" ng-repeat="i in m.enu[\''+conf.id+'\']">'
			+ '<input type="radio"' 
			+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
			+ ' id="${id}_{{p_index}}"'
			+ ' desc="'+ prop["i18nname-" + Parser.lang]+'"' 
			+ ' name="${id}" value="{{i[0]}}" '
			+ ' ng-model="b.${databinding}"'
			+ ' /><span class="ng-cloak1">{{i[1]}}</span>'
			+ '</label>'
			+ '<label class="ng-cloak1" for="${id}_{{i[0]}}">{{i[1]}}</label>'
			+ '</div>'
			+ '</div>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

Parser["control:radio:default:Json2htmlParser:html"] = function(confs) {
	var s = "";
	for (var c in confs) {
		var conf = confs[c];
		var prop = conf.id ? Parser.props[conf.id] : {};
		Parser.log(JSON.stringify(conf));
		Parser.log(JSON.stringify(prop));
		Parser.parseDataProvider(conf.id);
		var required = Parser.parseValidator(conf.id);
		Parser.parseI18ntip(conf.id);
		var data = {};
		data.id = conf.id;
		data.databinding = prop.databinding;
		data.style = Parser.cssDisplay(prop.display)+(prop.style?prop.style:"")+(prop.margintop?"margin-top:"+prop.margintop:"");
		var transform = {"tag":"i"};
		var fmdcols = parseInt(conf.fmdcols);
		var cols = [1,fmdcols-1];
		if(fmdcols>3) {
			cols = [2,fmdcols-2];
		}
		transform.html = '<span class="label col-md-'+cols[0]+'"'
				+ (data.style ? ' style="'+data.style+'"' : '')
				+ '><p'
				+ (prop["i18ntip-"+Parser.lang] ? (' title="'+prop["i18ntip-"+Parser.lang]+'"') : '')
				+ (prop.hideLabel=='1' ? ' style="display:none;"' : '')
				+ '>'
				+ (required ? '<span class="xh">*</span>' : '')
				+ prop["i18nname-"+Parser.lang]
				+ (prop["i18ntip-"+Parser.lang] ? ('&nbsp;<i class="glyphicon glyphicon-question-sign"></i>') : '')
				+ '</p>'
				+ '</span>'
				+ '<span class="item cellborder col-md-'+cols[1]+' '+(prop.classNames ? prop.classNames : '')+'"'
				+ (data.style ? ' style="'+data.style+'"' : '')
				+ '>'
				+ '<span id='+conf.id+'>'
				+ '<span class="'+(prop.horizontal=='1' ? 'radio-inline radioSpan-inline' : 'radio radioSpan')+'"ng-init="p_index=$index" ng-repeat="i in m.enu[\''+conf.id+'\']">'			
//				+ '<label class="checkbox-inline" for="${id}_{{i[0]}}" ng-repeat="i in m.enu[\''+conf.id+'\']">'
				+ '<label class='+(prop.horizontal=='1' ? 'radio-inline' : 'radio')
				+'><input class="" type="radio"'
				+ (prop.disabled=='1' ? ' disabled="disabled"' : '')
				+ ' id="'+conf.id+'_{{p_index}}"'
				+ ' desc="'+ prop["i18nname-" + Parser.lang]+'"' 
				+ ' name="'+conf.id+'" value="{{i[0]}}" '
				+ ' ng-model="b.'+prop.databinding+'"'
				+ ' /><span class="ng-cloak1">{{i[1]}}</span></label>'
				+ '</span>'
				+ '<span for="'+conf.id+'_{{i[0]}}">{{i[1]}}</span>'
				+ '</span>'
				 + (prop.attachment=='1' ? '<span class="attachspan" attach-tag="'+(prop.attachmentTag || conf.id)+'">'
						            + (prop.attachmentEditable=='1' ? '<button class="btnupload" title="'+fmd_i18n_prop_upattach+'">&nbsp;'+fmd_i18n_modules.input.attachment+'&nbsp;</button>' : '')
						            + '</span>' : '')

				+ '</span>';
		var wrapper = json2html.transform(data, transform);
		s += wrapper.substr(0, wrapper.length-4).substr(3);
	}
	return s;
};

